<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;

class DepartmentFile extends Model
{
    use HasDateTimeFormatter;
    protected $fillable = ['department_id', 'dwdm', 'ppt_filepath', 'pdf_filepath', 'extension', 'created_at', 'updated_at'];
    protected $table = 'department_files';

    #1述职材料或者班子  2个人考核材料或者班子领导 3党建材料
    const BZ_SHUZHI = 1; #述职材料或者班子考核表
    const BZ_PERSONAL = 2; #个人考核表
    const DJ_SHUZHI = 3;#党建述职PPT或者党建工作总结(pdf)

    const OFFICE_FILE_TYPE_PDF = 'pdf';
    const OFFICE_FILE_TYPE_PPT = 'ppt';

    const EXTENSION_PDF = ['pdf'];
    const EXTENSION_PPT = ['ppt'];

    public static function getAllFilesByDwdmAndOfficeFileType($dwdm, $office_file_type)
    {
        if ($office_file_type == 'ppt') {
            $extension = ['pptx'];
        }
        if ($office_file_type == 'pdf') {
            $extension = ['pdf'];
        }
        return DepartmentFile::query()->where('dwdm', $dwdm)->whereIn('extension', $extension)->get();
    }

    public function getFilePathByOfficeFileType($office_file_type)
    {
        if ($office_file_type == self::OFFICE_FILE_TYPE_PDF) {
            return $this->pdf_filepath;
        }
        if ($office_file_type == self::OFFICE_FILE_TYPE_PPT) {
            return $this->ppt_filepath;
        }
        return '';
    }
    
}